Skip to content

Matter Switch: Update table emptiness checks - #3223

Merged
hcarter-775 merged 1 commit into
mainfrom
fix/incorrect-table-removal
Sep 21, 2026
Merged

hcarter-775 merged 1 commit into
mainfrom
fix/incorrect-table-removal

Conversation

@hcarter-775

@hcarter-775 hcarter-775 commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Description of Change

Update method for checking table emptiness check to check whether next() is nil, to avoid issues with the '#' operator, which is invalid if keys are not ordered. Also, add and update some logging to be more useful via hub log methods.

Summary of Completed Tests

Tests added to check this works as expected, specifically for devices reporting endpoints out of order.
Tested on a physical TP-Link device that reports its endpoints out of order.

@github-actions

github-actions Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Channel deleted.

@github-actions

github-actions Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Test Results

   73 files    541 suites   0s ⏱️
3 266 tests 3 266 ✅ 0 💤 0 ❌
5 255 runs  5 255 ✅ 0 💤 0 ❌

Results for commit db0ec25.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

matter-switch_coverage.xml

File Coverage
All files 92% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/camera/camera_handlers/capability_handlers.lua 83% ❌
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/camera/camera_handlers/attribute_handlers.lua 96% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/eve_energy/init.lua 91% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/ikea_scroll/init.lua 90% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/switch_utils/utils.lua 92% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/switch_utils/device_configuration.lua 97% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/third_reality_garage_door/init.lua 97% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/camera/camera_utils/device_configuration.lua 96% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/camera/camera_utils/utils.lua 99% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/camera/init.lua 97% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/switch_handlers/attribute_handlers.lua 81% ❌
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/switch_handlers/capability_handlers.lua 92% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/switch_handlers/event_handlers.lua 97% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/ikea_scroll/scroll_utils/event_utils.lua 52% ❌
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/hager/init.lua 93% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/aqara_cube/init.lua 95% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/third_reality_mk1/init.lua 93% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/init.lua 97% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/ikea_scroll/scroll_handlers/event_handlers.lua 75% ❌

Minimum allowed coverage is 90%

Generated by 🐒 cobertura-action against db0ec25

@cjswedes cjswedes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont fully understand why this change is necessary. The fields we are storing should be either exclusively using the array portion of the table or we should assume they could be using the hash portion. It seems like for this driver, we need to assume there could be a hash portion because the endpoints could be out of order; we should use pairs. If the fields are a list, we can use table.remove and rely on the # operator.

@hcarter-775

hcarter-775 commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor Author

I dont fully understand why this change is necessary. The fields we are storing should be either exclusively using the array portion of the table or we should assume they could be using the hash portion. It seems like for this driver, we need to assume there could be a hash portion because the endpoints could be out of order; we should use pairs. If the fields are a list, we can use table.remove and rely on the # operator.

@cjswedes This change is mostly required to add the table.remove operator. Everything else is not technically necessary, but I do think the # operator has drawbacks that make me lean towards not using it as a generic function (hence why I now added an is_field_empty fn). I agree it would be fine now, but I still would prefer not to use it since it is unreliable in a handful of cases. As for pairs vs. ipairs, this isn't a huge difference anyway but I see what you mean.

So seems to me that your main concern is why we wouldn't use the # operator, considering what the shape of the field appears to be otherwise? I suppose I'd say it would purely be to keep things more generic, but I'm open to other ideas.

@hcarter-775

Copy link
Copy Markdown
Contributor Author

@cjswedes Read your message again, to more completely answer your question, the actual bug this fixes is that the previous "remove index from table" logic simply set the index to nil, and did not call table.remove. This lead to a case where the # operator saw the table as being empty when it actually wasn't.

end
end
if #set_topology_eps == 0 then -- in other words, all AvailableEndpoints attribute responses have been handled
if switch_utils.is_field_empty(device, fields.ELECTRICAL_SENSOR_EPS) then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this helper actually makes understanding the layout of the field less clear. If we know this is a list and can use ipairs, then # is sufficient.

@hcarter-775
hcarter-775 force-pushed the fix/incorrect-table-removal branch from 82a207b to db0ec25 Compare September 21, 2026 16:04
@hcarter-775 hcarter-775 changed the title Matter Switch: Update table removal method, update table emptiness checks Matter Switch: Update table emptiness checks Sep 21, 2026
@hcarter-775
hcarter-775 merged commit 9274833 into main Sep 21, 2026
16 of 22 checks passed
@hcarter-775
hcarter-775 deleted the fix/incorrect-table-removal branch September 21, 2026 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants